// 获取当前日期
import dayjs from 'dayjs';
export const curDate = dayjs().format('YYYY-MM-DD');
// 输出: 2021-09-17
// 出生日期格式
export function formBirthDate(date) {
  const date1 = date.replace(/[^0-9]/gi, '-');
  const year = date1.split('-')[0];
  const mm = parseInt(date1.split('-')[1]);
  const month = mm + 1 >= 10 ? mm : '0' + mm;
  const day = date1.split('-')[2];
  console.log(year + month + day);
}
/**
 * 两个日期大小比较
 * @param d1 YYYY-MM-dd
 * @param d2 YYYY-MM-dd
 * @returns {Boolean}
 */
export function compareDate(d1, d2) {
  return new Date(d1.replace(/-/g, '/')) >= new Date(d2.replace(/-/g, '/'));
}

// 获取两个日期相差的天数
export function getDaysBetween(dateString1, dateString2) {
  const startDate = Date.parse(dateString1);
  const endDate = Date.parse(dateString2);
  return (startDate - endDate) / (1 * 24 * 60 * 60 * 1000);
}
// 解析时间戳
export function parseTime(time, bool) {
  var date = new Date(time);
  var year = date.getFullYear();
  var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  if (!bool) {
    return year + '/' + month + '/' + day;
  } else {
    return year + '-' + month + '-' + day + ' ' + h + ':' + m + ':' + s;
  }
}
